/*
 * user_config.h
 *
 *  Created on: 2025.6.25
 *      Author: TracyHenry
 */

#ifndef USER_CONFIG_H_
#define USER_CONFIG_H_

#include "FreeRTOS.h"
#include "task.h"
#include "stm32f1xx_hal.h"
#include "cmsis_os.h"


#define Storage_TimeList_ADDRESS_Sector            (0)
#define Storage_Num_ADDRESS_Sector                 (1*4096)
#define Storage_Device_Info_Sector                 (2*4096)
#define Storage_Feed_Stategy_Info_Sector           (3*4096)
#define Storage_WaterMarkSensor_Config_Info_Sector (4*4096)
#define Storage_StaticData_Info_Sector             (5*4096)
#define Storage_Alarm_Config_Info_Sector           (6*4096)

#define MotorNumMax 3
#define FeedNumMax 10

#define SOFTWARE_VERSION "version1.0.0"

typedef struct QueueSetParamEvent
{
   uint8_t event;
   uint8_t data[16];
   uint8_t len;
} QueueSetParamEvent;

typedef struct DEVICE_INFO
{
   char deviceSN[32];
   uint16_t deviceType;
   char deviceVersion[12];
   uint8_t motorNum;
   uint8_t motorNo[MotorNumMax];
   uint8_t motorDirection[MotorNumMax];
   uint8_t motorSpeed[MotorNumMax];
   uint8_t motorRotationAmount[MotorNumMax];
   uint8_t motorTimeStrategy[MotorNumMax];
   uint16_t motorStatus[MotorNumMax];
} DEVICE_INFO;
//68byte

typedef struct FeedStrategy
{
   uint16_t dayAge;
   uint16_t pigNum;
   uint16_t waterFeedRatio;
   uint8_t startHour;
   uint8_t startMinute;
   uint8_t endHour;
   uint8_t endMinute;
   uint8_t operationMode;
   uint8_t timeMode;
   uint8_t livestockFeedMode;
   uint8_t idleMode;
   uint8_t waterFeedMode;
   uint8_t feedMode;
   uint16_t singleMaxLivestockFeedAmount;//
   uint16_t singleMaxWaterFeedAmount;
   uint8_t feedTimeInterval;
   uint8_t feedAndWaterTimeInterval;
   uint8_t waterFeedTimeInterval;
   uint8_t cycleTimePeriod;//
   uint8_t feedCount; 
   // uint8_t feedStartTimeHour[FeedNumMax];//
   // uint8_t feedStartTimeMinute[FeedNumMax];//
   uint8_t feedTimePeriod;//
   uint16_t feedCaculateConfigure1;//
   uint16_t feedCaculateConfigure2;//
} FeedStrategy;
//52byte

typedef struct WaterMarkSensorConfigInfo {
   uint8_t type;
   uint16_t delayTime;
   uint16_t duty;
   uint16_t configure3;
} WaterMarkSensorConfigInfo;
//8byte

typedef struct StaticDataInfo {
   uint32_t dayTotalFeedAmount;
   uint32_t dayTotalWaterFeedAmount;
   uint32_t lastDayTotalFeedAmount;
   uint32_t lastDayTotalWaterFeedAmount;
} StaticDataInfo;
//16byte

typedef struct AlarmConfigInfo
{
   uint8_t dayByDayFeedUpperLimit;
   uint8_t dayByDayFeedLowLimit;
   uint8_t dayByDayWaterFeedUpperLimit;
   uint8_t dayByDayWaterFeedLowLimit;
   uint8_t feedAmoutUpperLimit;
   uint8_t feedAmoutLowLimit;
   uint8_t waterFeedAmoutUpperLimit;
   uint8_t waterFeedAmoutLowLimit;
}AlarmConfigInfo;
//8byte

typedef enum COMMAND_Send
{
     UDP_Set_Motor_Start_Stop = 1,
     UDP_Set_Device_Time = 2,
     UDP_Set_Time_Tasks = 3,
     UDP_Get_Motor_Status = 4,
     UDP_Get_Device_Time = 5,
     UDP_Get_Time_Tasks = 6,
     UDP_Set_Motor_Speed = 7,
     UDP_Set_Motor_Direction = 8,
     MQTT_Set_Motor_Param = 9,
     MQTT_Set_Feed_Base_Param = 10,
     MQTT_Set_Operation_Mode = 11,
     MQTT_Set_Feed_Mode = 12,
     MQTT_Set_LiveStocksFeed_Mode = 13,
     MQTT_Set_Time_Mode = 14,
     MQTT_Set_LiveStockWaterOrder_Mode = 15,
     MQTT_Set_IdleWater_Param = 16,
     MQTT_Set_CycleFeedTime_Param = 17,
     MQTT_Get_Feed_Base_Param = 18,
     MQTT_Get_Operation_Mode = 19,
     MQTT_Get_Feed_Mode = 20,
     MQTT_Get_LiveStocksFeed_Mode = 21,
     MQTT_Get_Time_Mode = 22,
     MQTT_Get_LiveStockWaterOrder_Mode = 23,
     MQTT_Get_IdleWater_Param = 24,
     MQTT_Get_CycleFeedTime_Param = 25,
     MQTT_Get_Motor_Status = 26,
     MQTT_Get_SoftWare_Version = 27
}COMMAND_Send;

#endif /* USER_CONFIG_H_ */
